package com.prj.ufdm.demo.tutorial.hadoop.mr;

import java.io.IOException;
import java.util.StringTokenizer;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
/**
 * 分词器Mapper
 * @author Administrator
 */
public class WordCountMapper extends Mapper<Object, Text, Text, IntWritable>{
	
	private final static IntWritable one = new IntWritable(1);
    private Text wordText = new Text();

	public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
		
		System.out.println("\n Mapper key="+key + ", value="+value.toString());
		
		StringTokenizer itr = new StringTokenizer(value.toString());
		while (itr.hasMoreTokens()) {
			wordText.set(itr.nextToken());
			context.write(wordText, one);
		}
		
	}
    
}
